package net.coolskill.demo.springboot.aop;

import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.stereotype.Component;

public class ProfilerPointcutAdvisor implements PointcutAdvisor {

    private final AnnotationMatchingPointcut pointcut
        = new AnnotationMatchingPointcut(Component.class, ProfilerMonitor.class);
    private final ProfilerAdvice advice = new ProfilerAdvice();

    @Override
    public Pointcut getPointcut() {
        return pointcut;
    }

    @Override
    public Advice getAdvice() {
        return advice;
    }

    @Override
    public boolean isPerInstance() {
        return false;
    }

    private static class ProfilerAdvice implements MethodInterceptor {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            return invocation.proceed();
        }
    }
}
